package com.wrk._3_方法._02_习题;

public class _001_复制数组 {
    public static void main(String[] args) {
        //定义原始数组
        int [] arr = new int[]{1, 2, 4, 90, 18, 17};
        //定义复制数组
        int [] copyarr = copyOfRange(arr, 2, 5);
        //遍历数组输出
        for (int i = 0; i < copyarr.length; i++) {
            System.out.print(copyarr[i]+"\t");
        }
    }
    //定义方法，将原始数组元素赋值给新数组，包含from，不包含to
    public static int [] copyOfRange(int[] arr,int from, int to){
        //定义新数组
        int [] array = new int[to - from];
        //遍历数组
        int a=0;
        for (int i = from - 1; i < to - 1; i++) {
            array[a++] = arr[i];
        }
        return array;
    }
}
